package ubi.quando.UI;

import java.util.Date;

import ubi.quando.App.EventBase;
import ubi.quando.App.EventMeeting;
import ubi.quando.App.EventType;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class ArrangeMeetingActivity extends ArrangeEventBaseActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mLoutLoc.setVisibility(View.GONE);
		mLocationDisplay.setVisibility(View.GONE);
		mChooseLocationBtn.setVisibility(View.GONE);
	}

	@Override
	protected void InitializeEvent() {
		mEvent = new EventMeeting(null, new Date(), mApp.getId(), null);
	}

	protected void onResume() {
		super.onResume();
		mApp.setCurrentActivity(this);

		Bundle b = getIntent().getExtras();
		if (b != null) {
			mEvent = (EventMeeting) b.getSerializable(EventBase.SerializeName);
		}

		updateDisplay();
	}

	@Override
	protected void SetEventType(Bundle b) {
		if (b != null) {
			EventType type = EventType.MEETING;
			saveEventTypeToBundle(type, b);
		}
	}

	@Override
	protected void AddParticipants(View v) {
		Intent addParticipants = new Intent(v.getContext(),
				AddParticipantsMeetingActivity.class);

		Bundle b = new Bundle();
		SetEventType(b);

		saveEventToBundle(b);
		addParticipants.putExtras(b);

		startActivity(addParticipants);
	}

	protected void ConfirmEvent(View v) {
		if (!IsEventValid()) {
			return;
		}

		EventMeeting event = (EventMeeting) mEvent;
		String eventId = mApp.getServerComm().createMeetingEvent(event.getAwaiting()
				.keySet(), event.GetName(), event.GetDestination(), event.GetDate(), mApp
				.getId());
		if (eventId != null) {
			mEvent.setId(eventId);
			mApp.addEvent(mEvent);
		} else {
			Toast.makeText(getApplicationContext(), "Event creation failed",
					Toast.LENGTH_SHORT).show();
		}
		super.ConfirmEvent(v);
	}
}
